package net.lab1024.sa.admin.module.users.controller;

import net.lab1024.sa.admin.module.users.domain.form.UsersAddForm;
import net.lab1024.sa.admin.module.users.domain.form.UsersQueryForm;
import net.lab1024.sa.admin.module.users.domain.form.UsersUpdateForm;
import net.lab1024.sa.admin.module.users.domain.vo.UsersVO;
import net.lab1024.sa.admin.module.users.service.UsersService;
import net.lab1024.sa.base.common.domain.ValidateList;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import cn.dev33.satoken.annotation.SaCheckPermission;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 实训室管理系统 Controller
 *
 * @Author 王俊权
 * @Date 2024-11-06 10:32:24
 * @Copyright 🐂🐎bloc
 */

@RestController
@Tag(name = "实训室管理系统")
public class UsersController {
    //更改

    @Resource
    private UsersService usersService;

    @Operation(summary = "分页查询 @author 王俊权")
    @PostMapping("/users/queryPage")
    @SaCheckPermission("users:query")
    public ResponseDTO<PageResult<UsersVO>> queryPage(@RequestBody @Valid UsersQueryForm queryForm) {
        return ResponseDTO.ok(usersService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author 王俊权")
    @PostMapping("/users/add")
    @SaCheckPermission("users:add")
    public ResponseDTO<String> add(@RequestBody @Valid UsersAddForm addForm) {
        return usersService.add(addForm);
    }

    @Operation(summary = "更新 @author 王俊权")
    @PostMapping("/users/update")
    @SaCheckPermission("users:update")
    public ResponseDTO<String> update(@RequestBody @Valid UsersUpdateForm updateForm) {
        return usersService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author 王俊权")
    @PostMapping("/users/batchDelete")
    @SaCheckPermission("users:delete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Integer> idList) {
        return usersService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author 王俊权")
    @GetMapping("/users/delete/{id}")
    @SaCheckPermission("users:delete")
    public ResponseDTO<String> batchDelete(@PathVariable Integer id) {
        return usersService.delete(id);
    }
}
